package com.zl.service;

import com.zl.beans.NewsLabel;
import com.zl.beans.Page;
import com.zl.dao.NewsLabelDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsLableServiceImpl implements NewsLableService {

    @Autowired
    private NewsLabelDao newsDao;
    @Override
    public Page<NewsLabel> findCurrentPage(int pagenum) {
        Page<NewsLabel> page = new Page();
        page.setPagenum(pagenum);
        int totalRows = newsDao.selectRows();
        page.setTotalRows(totalRows);
        List<NewsLabel> datas = newsDao.selectCurrentPageNewsLabels(page);
        page.setDatas(datas);
        return page;
    }

    @Override
    public Page<NewsLabel> findLibels() {
        Page<NewsLabel> page = new Page();
        List<NewsLabel> datas = newsDao.selectLabels();
        page.setDatas(datas);
        return page;
    }

    @Override
    public void addLabel(String labelName, String labelContent,Integer pid) {
        newsDao.insertLabel(labelName,labelContent,pid);
    }
    /*删除*/
    @Override
    public void rmLabel(Integer id) {
        newsDao.delectLabelById(id);
    }

    @Override
    public Page<NewsLabel> findChild(Integer id) {
        Page<NewsLabel> page = new Page();
        int childRows = newsDao.selectChildRows(id);
        page.setTotalRows(childRows);
        List<NewsLabel> datas = newsDao.selectChild(id);
        page.setDatas(datas);
        return page;
    }
    @Override
    public void updateLabel(String labelName, String labelContent, Integer id,Integer pid) {
        newsDao.changeLabel(labelName,labelContent,id,pid);
    }
    @Override
    public NewsLabel SelectLabelById(Integer id) {
        NewsLabel newsLabel = newsDao.findLabelById(id);
        return newsLabel;
    }
}
